import os

from django.shortcuts import render,redirect,HttpResponse
from django.contrib import redirects

from vipuser.settings import BASE_DIR
from .models import *
from django.urls import reverse
from django.views import View
from django.core.paginator import Paginator
# Create your views here.

class Show(View):
    def get(self,request,page=1):
        data=member.objects.all()
        pager=Paginator(data,1)
        pagee=pager.get_page(page)
        return render(request,'index.html',locals())

class Add(View):
    def get(self,request):
        data=membership.objects.all()
        return render(request,'add.html',{'data':data})
    def post(self,request):
        name=request.POST.get('name')
        phone=request.POST.get('phone')
        joinDate=request.POST.get('joinDate')
        ship=request.POST.get('ship')
        member.objects.create(name=name,phone=phone,joinDate=joinDate,ship_id=ship)
        return redirect(reverse('usermanage:show'))

def ABC(request):
    if request.method == 'POST':
        myfileobj = request.FILES.get('myfile')
        f = open(os.path.join(BASE_DIR, 'static', 'pic', myfileobj.name), 'wb')
        for chunk in myfileobj.chunks():
            f.write(chunk)
        f.close()
        return HttpResponse("上传成功")





